{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "81c286bf",
   "metadata": {},
   "source": [
    "## 上周回顾\n",
    ">* list一般方法/函数的所有的使用场景及案例\n",
    ">>1.append()\n",
    ">>2. pop(index)\\remove(values)\n",
    ">>3.count()\n",
    ">>4.index()\n",
    ">>5.extend()\n",
    ">>6.sort()\n",
    ">>...\n",
    ">* list 高级用法 如：\n",
    ">>1.copy() 复制 不等于赋值，复制可等价于切片[:]\n",
    ">>2.enumerate\n",
    ">* 课本练习（课堂上已做） don't panic ==> on tap 其中知识点：\n",
    ">>1.list 的一些方法实现\n",
    ">>2.list 的切片实现\n",
    ">>3.str =》list 方法 list(str)\n",
    ">>4.list => str的方法 ‘’。join（list）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29a889c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 本周内容\n",
    "\n",
    "### 先做一些简单的练习\n",
    ">* 1.vowels2.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e71c28f",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']# 这是元音(list)\n",
    "word = 'mlliiways'# 这是文本(str)\n",
    "# 需求： word 中出现的 vowels 打印出来\n",
    "for letter in word: \n",
    "# 可任意取名的  指循环遍历的变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66e49384",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']# 这是元音(list)\n",
    "word = 'mlliiways'# 这是文本(str)\n",
    "# 需求： word 中出现的 vowels 打印出来\n",
    "for letter in word: \n",
    "# 可任意取名的  指循环遍历的变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "534873a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "for word in vowels：# 循环遍历的第一个位置的元素请注意名字\n",
    "                    # 不要和已定义过的变量重复\n",
    "    print(word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e38e246",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in vowels: # for循环的第二个元素，决定了我们循环的内容\n",
    "    print(i)     #  循环的列表，每个元素在一行打印"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78650f73",
   "metadata": {},
   "outputs": [],
   "source": [
    "for letter in word: # letter 可以随便命名，不会影响结果\n",
    "                    #一般情况下：item(内容) => 简写：i \n",
    "    # print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8ac1d18",
   "metadata": {},
   "outputs": [],
   "source": [
    " # append()常用于新建列表\n",
    "found[]\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a43c133",
   "metadata": {},
   "outputs": [],
   "source": [
    "# input输入\n",
    "# 字符串转换数字\n",
    "# for 循环\n",
    "# 条件判断\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "071c8eb3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备工作：\n",
    "# 1.商品信息：\n",
    "goods_list = [  \n",
    "    ['巧克力',9],\n",
    "    [ '烤鸡',35],\n",
    "    ['牛肉卷',28],\n",
    "    ['麦旋风',12]\n",
    "    ]\n",
    "# 2. 用户购物信息\n",
    "user_shopping_list = []\n",
    "# 用户输入(余额)： #-------知识点：打印与用户输入-------\n",
    "Alipay = int(input('请输入您的支付宝余额：')) # 此处int 强制将字符串改为数据值\n",
    "#info = '''----------goods list----------'''\n",
    "#编号0，商品名称：%s，商品的价格:%s 元\n",
    "#编号1，商品名称：%s，商品的价格:%s 元   \n",
    "#编号2，商品名称：%s，商品的价格:%s 元\n",
    "#编号3，商品名称：%s，商品的价格:%s 元\n",
    "#'''%(goods_list[0][0],goods_list[0][1]\n",
    " #  goods_list[1][0],goods_list[1][1]\n",
    "  # goods_list[2][0],goods_list[2][1]\n",
    "   #goods_list[3][0],goods_list[3][1])\n",
    "   #print(info)\n",
    "whlie True:\n",
    "print('----------goods list----------')\n",
    "# for循环的优势，节省重复代码的书写\n",
    "for i in range(5): # i是0,1,2,3，\n",
    "    print('编号%s，商品名称：%s，商品的价格:%s 元'\n",
    "    %(i,goods_list[i][0],goods_list[i][1]))\n",
    "    ## 用户输入商品编号：\n",
    "    choice = int(input('请输入购买商品的编号：'))\n",
    "    ## 1.输入编号的存在，判断余额是否足够\n",
    "    if choice < len(goods_list):\n",
    "        ### 1.余额足够，用户余额—商品价格\n",
    "        if goods_list[choice][1] < Alipay:\n",
    "            Alipay  = Alipay - goods_list[choice][1]\n",
    "            user_shopping_list.append(good_list[choice])\n",
    "            print(您的商品购买成功，已添加到购物车，您的余额还有%s。%(Alipay))\n",
    "          ###2.余额不够，‘您的余额不足’\n",
    "        else:\n",
    "            print:('您的余额不足')\n",
    "    else:\n",
    "        print('您输入的商品编号可能超过我们的商品范围或不存在这个商品')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f5a82d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "users_shop_data = ['A','B','C']\n",
    "users_shop_password = ['111','222','333']\n",
    "Alipay = ['300','500','700']\n",
    "\n",
    "import time\n",
    "Time =time.strftime('%Y-%m-%d')\n",
    "print(Time,'wellcome to the market!')\n",
    "\n",
    "username = input('请输入您的账号：')\n",
    "password = input('请输入您的密码：')\n",
    "if username in users_shop_data:\n",
    "    if password in users_shop_password:\n",
    "        print('欢迎%s登录supermarket'%(username))\n",
    "else:\n",
    "    print('您输入的账号密码错误，请重新输入！')\n",
    "\n",
    "goods_list = [  \n",
    "    ['巧克力',9],\n",
    "    [ '烤鸡',35],\n",
    "    ['牛肉卷',28],\n",
    "    ['雪糕',12],\n",
    "    ['电视机',2000]\n",
    "    ]\n",
    "\n",
    "user_shopping_list = []\n",
    "Alipay = int(input('请输入您的支付宝余额：'))\n",
    "print('----------goods list----------')\n",
    "while True:\n",
    "    for i in range(5): \n",
    "        print('编号%s，商品名称：%s，商品的价格:%s 元'\n",
    "        %(i,goods_list[i][0],goods_list[i][1]))\n",
    "    ## 用户输入商品编号：\n",
    "    choice = int(input('请输入购买商品的编号：'))\n",
    "    if choice < len(goods_list):\n",
    "         ### 1.余额足够，用户余额—商品价格\n",
    "        if goods_list[choice][1] < Alipay:\n",
    "            Alipay  = Alipay - goods_list[choice][1]\n",
    "            user_shopping_list.append(goods_list[choice])\n",
    "            print(user_shopping_list)\n",
    "            print('您的商品购买成功，已添加到购物车，您的余额还有%s。'%(Alipay))\n",
    "            break\n",
    "          ###2.余额不够，‘您的余额不足’\n",
    "        else:\n",
    "            if goods_list[choice][1]>Alipay:\n",
    "                print:('您的余额不足,无法购买此商品。')\n",
    "    else:\n",
    "        if choice > len(goods_list):\n",
    "        print('您输入的商品编号可能超过我们的商品范围或不存在这个商品')\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "489fb6de",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "132fd8a5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b5c6285",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "622a67ae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
